package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.mapper.OrderMapper;
import com.zhentao.pojo.Torder;
import com.zhentao.service.OrderService;
import com.zhentao.vo.OrderQuery;
import org.springframework.stereotype.Service;

/**
* @author Lenovo
* @description 针对表【order(订单表)】的数据库操作Service实现
* @createDate 2025-08-06 18:32:19
*/
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Torder>
    implements OrderService{


    //门诊缴费记录
    @Override
    public IPage<Torder> pageQuery(OrderQuery orderQuery) {
        Page<Torder> page = new Page<>(orderQuery.getPageNum(), orderQuery.getPageSize());
        QueryWrapper<Torder> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("biz_type", "门诊缴费");

        if (orderQuery.getStartOperateTime() != null) {
            queryWrapper.ge("operate_time", orderQuery.getStartOperateTime());
        }
        if (orderQuery.getEndOperateTime() != null) {
            queryWrapper.le("operate_time", orderQuery.getEndOperateTime());
        }
        if (orderQuery.getCardId() != null) {
            queryWrapper.eq("card_id", orderQuery.getCardId());
        }


        if (orderQuery.getDeptId() != null) {
            queryWrapper.eq("dept_id", orderQuery.getDeptId());

        }

        return baseMapper.selectPage(page, queryWrapper);

    }

    //门诊充值记录
    @Override
    public IPage<Torder> pageQueryRecharge(OrderQuery orderQuery) {
        Page<Torder> page = new Page<>(orderQuery.getPageNum(), orderQuery.getPageSize());
        QueryWrapper<Torder> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("biz_type", "门诊充值");

        if (orderQuery.getStartOperateTime() != null) {
            queryWrapper.ge("operate_time", orderQuery.getStartOperateTime());
        }
        if (orderQuery.getEndOperateTime() != null) {
            queryWrapper.le("operate_time", orderQuery.getEndOperateTime());
        }
        if (orderQuery.getCardId() != null) {
            queryWrapper.eq("card_id", orderQuery.getCardId());
        }


        if (orderQuery.getDeptId() != null) {
            queryWrapper.eq("dept_id", orderQuery.getDeptId());

        }

        return baseMapper.selectPage(page, queryWrapper);

    }

//住院消费记录

    @Override
    public IPage<Torder> pageQueryXf(OrderQuery orderQuery) {
        Page<Torder> page = new Page<>(orderQuery.getPageNum(), orderQuery.getPageSize());
        QueryWrapper<Torder> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("biz_type", "住院缴费");

        if (orderQuery.getStartOperateTime() != null) {
            queryWrapper.ge("operate_time", orderQuery.getStartOperateTime());
        }
        if (orderQuery.getEndOperateTime() != null) {
            queryWrapper.le("operate_time", orderQuery.getEndOperateTime());
        }
        if (orderQuery.getCardId() != null) {
            queryWrapper.eq("card_id", orderQuery.getCardId());
        }


        if (orderQuery.getDeptId() != null) {
            queryWrapper.eq("dept_id", orderQuery.getDeptId());

        }

        return baseMapper.selectPage(page, queryWrapper);

    }

    //住院充值记录
    @Override
    public IPage<Torder> pageQueryCz(OrderQuery orderQuery) {
        Page<Torder> page = new Page<>(orderQuery.getPageNum(), orderQuery.getPageSize());
        QueryWrapper<Torder> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("biz_type", "住院充值");

        if (orderQuery.getStartOperateTime() != null) {
            queryWrapper.ge("operate_time", orderQuery.getStartOperateTime());
        }
        if (orderQuery.getEndOperateTime() != null) {
            queryWrapper.le("operate_time", orderQuery.getEndOperateTime());
        }
        if (orderQuery.getCardId() != null) {
            queryWrapper.eq("card_id", orderQuery.getCardId());
        }


        if (orderQuery.getDeptId() != null) {
            queryWrapper.eq("dept_id", orderQuery.getDeptId());

        }

        return baseMapper.selectPage(page, queryWrapper);
    }
    //退款记录
    @Override
    public IPage<Torder> pageQueryTk(OrderQuery orderQuery) {
        Page<Torder> page = new Page<>(orderQuery.getPageNum(), orderQuery.getPageSize());
        QueryWrapper<Torder> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("biz_type", "就诊卡退款");

        if (orderQuery.getStartOperateTime() != null) {
            queryWrapper.ge("operate_time", orderQuery.getStartOperateTime());
        }
        if (orderQuery.getEndOperateTime() != null) {
            queryWrapper.le("operate_time", orderQuery.getEndOperateTime());
        }
        if (orderQuery.getCardId() != null) {
            queryWrapper.eq("card_id", orderQuery.getCardId());
        }


        if (orderQuery.getDeptId() != null) {
            queryWrapper.eq("dept_id", orderQuery.getDeptId());

        }

        return baseMapper.selectPage(page, queryWrapper);
    }


}




